#include <bits/stdc++.h>
#define int long long
using namespace std;
typedef pair< int,int > pii;

int inline read(){
    int x = 0,f = 1;char c = getchar();
    while(!isdigit(c)){if(c == '-')f = -1;c=getchar();}
    while(isdigit(c)){x = x * 10 + c - '0';c=getchar();}
    return x*f;
}

int s[200005];

signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T = read();
    for(int i = 1;i <= T;i++){
        int n = read(),tt=0;
        for(int i=1;i<=n;i++){
            s[i]=read();
            tt+=s[i];
        }
        if(n == 1)cout << 1 << endl;
        else cout << rand()%tt << endl;
    }

    return 0;
}
